package com.rem.rabbitmq.boot.Bconfirm;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Rem
 * @date 2021-12-29
 */

@Configuration
public class ConfirmConfig {

    /**
     * 发布确认交换机 队列 routingKey
     */
    public static final String CONFIRM_EXCHANGE = "CONFIRM_EXCHANGE";

    public static final String CONFIRM_ROUTING_KEY = "CONFIRM_ROUTING_KEY";

    public static final String CONFIRM_QUEUE = "CONFIRM_QUEUE";

    /**
     * 声明业务交换机
     *
     * @return
     */
    @Bean("confirmExchange")
    public DirectExchange confirmExchange() {
        return ExchangeBuilder.directExchange(CONFIRM_EXCHANGE).build();
    }

    /**
     * 声明发布确认队列
     *
     * @return
     */
    @Bean("confirmQueue")
    public Queue confirmQueue() {
        return QueueBuilder.durable(CONFIRM_QUEUE).build();
    }

    /**
     * 声明绑定关系
     *
     * @param confirmQueue
     * @param confirmExchange
     * @return
     */
    @Bean
    public Binding confirmQueueaBinding(@Qualifier("confirmQueue") Queue confirmQueue, @Qualifier("confirmExchange") DirectExchange confirmExchange) {
        return BindingBuilder.bind(confirmQueue).to(confirmExchange).with(CONFIRM_ROUTING_KEY);
    }


}
